package com.zyh.controller;

import com.zyh.entity.Type;
import com.zyh.service.BookService;
import com.zyh.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;
    @Autowired
    private BookService bookService;
    @Autowired
    private ModelAndView mav;

    @RequestMapping("selectAllTypeMvc")
    public ModelAndView selectAllTypeMvc(){
        List<Type> typeList = typeService.selectTypes();
        mav.addObject("typeList",typeList);
        mav.setViewName("/addBook.jsp");
        return mav;
    }
    @RequestMapping("selectAllByPageMvc")
    public ModelAndView selectAllByPageMvc(){
        List<Type> typeList = typeService.selectTypes();
        mav.addObject("typeList",typeList);
        mav.setViewName("/typelist.jsp");
        return mav;
    }
    @RequestMapping("deleteByTypeIdMvc")
    public ModelAndView deleteByTypeIdMvc(Integer typeId){
        bookService.deletesByTypeId(typeId);
        typeService.deleteByTypeId(typeId);
        mav.setViewName("redirect:/type/selectAllByPageMvc.do");
        return mav;
    }

}
